package com.zoranjoka.chordis.spring;

import java.io.Serializable;
import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional;

import com.zoranjoka.chordis.Artist;
import com.zoranjoka.chordis.beans.ArtistBean;
import com.zoranjoka.chordis.hibernate.IDataArtistService;

public class DataArtistDAO implements IDataArtistService {
	private SessionFactory sessionFactory;

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Transactional
	public List<ArtistBean> getAllArtists() {
		List all = sessionFactory.getCurrentSession().createQuery("from ArtistBean").list();
        return all;
	}

	@Transactional
	public Artist getArtistByName(Serializable id) {
		return (Artist) sessionFactory.getCurrentSession().get(ArtistBean.class, id);
	}

	@Transactional
	public Artist addArtistBean(Artist ab) {
		Long id = (Long) sessionFactory.getCurrentSession().save(ab);
		return (Artist) sessionFactory.getCurrentSession().get(
				ArtistBean.class, id);
	}
}
